//
//  QCTabBarController.m
//  Hyatt
//
//  Created by QC.L on 15/5/25.
//  Copyright (c) 2015年 QC.L. All rights reserved.
//

#import "QCTabBarController.h"

@interface QCTabBarController ()
@property (nonatomic, strong) UIView *tabBarView;
@end

@implementation QCTabBarController

- (void)setViewControllers:(NSArray *)viewControllers
{
    _viewControllers = [viewControllers copy];
    for (UIViewController *view in _viewControllers) {
        // 遍历ViewController将其添加到容器视图控制器中
        [self addChildViewController:view];
    }
    self.tabBarView = [[UIView alloc] initWithFrame:CGRectMake(-1, kHeight - 50, kWidth + 2, 50)];
    self.tabBarView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.tabBarView.layer.borderWidth = 1;
    [self.view addSubview:self.tabBarView];
    CGFloat width = kWidth / self.viewControllers.count;
    for (int i = 0; i < self.viewControllers.count; i++) {
        if ([self.viewControllers[i] isKindOfClass:[UINavigationController class]]) {
            UINavigationController *view = (UINavigationController *)self.viewControllers[i];
            UIViewController *view1 = view.viewControllers[0];
            NSLog(@"%@", view1.tabBarItem.title);
        } else {
            UIViewController *view = self.viewControllers[i];

        }

    }


}


+ (UIViewController *)creatViewControllerWithName:(NSString *)className isHaveNavgation:(BOOL)isHave tabTitle:(NSString *)tittle tabImage:(NSString *)image
{
    // 根据类名创建类
    Class class = NSClassFromString(className);
    // 根据类创建对象(多态)
    UIViewController *view = [[class alloc] init];
    
    view.tabBarItem = [[UITabBarItem alloc] initWithTitle:tittle image:[UIImage imageNamed:image] tag:0];
    // 判断是否存在导航控制器
    if (isHave) {
        // 存在就创建导航控制器
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];
        // 返回导航控制器
        return nav;
    } else {
        // 否则直接返回
        return view;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
